package ywpt.service.config;

import java.util.List;

import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.ScanType;
import ywpt.web.common.PublicFunction;
@Service("scanTypeService")
@RemoteProxy(name="scanTypeService")
public class ScanTypeServiceImpl  extends HibernateEntityDao<ScanType> implements ScanTypeService{
	public ScanTypeServiceImpl() {
		
	}

	@Override
	public String createScanTypeCode() {
		DetachedCriteria query = DetachedCriteria.forClass(ScanType.class, "scanType");
		String typeCode="";
		String code="";
		Integer maxId=new Integer(0);
		query.addOrder(Order.desc("id"));
		List<ScanType> scanTypes = this.getScanTypes(query);
		if ( scanTypes.iterator().hasNext() )	
		{
			code = scanTypes.iterator().next().getCode();		
			maxId = new Integer(code);
		}
		typeCode=PublicFunction.getNextCode("", maxId, false,3); 
		return typeCode;
	}

	@Override
	public ScanType getScanTypeById(Long id) {
		return this.get(id);
	}

	@Override
	public int getScanTypeCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ScanType> getScanTypes(DetachedCriteria query, int pageSize,
			int startIndex) {
		return this.findAllByCriteria(query, pageSize, startIndex);
	}

	@Override
	public void removeScanType(Long id) {
		super.removeById(id);
	}

	@Override
	public void saveScanType(ScanType scanType) {
		super.save(scanType);
	}

	@Override
	public void updatScanType(ScanType scanType) {
		super.save(scanType);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ScanType> getScanTypes(DetachedCriteria query) {
		return this.findAllByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	@RemoteMethod
	public List<ScanType> getAllScanTypes() {
		DetachedCriteria query = DetachedCriteria.forClass(ScanType.class);
		return this.findAllByCriteria(query);
	}
 
	
	
}
